<?php
@include_once ( 'Smarty.class.php' );


class Exts_Smarty
{

    /** Used to define the inline template */

// put these function somewhere in your application
    public function inline_get_template( $tpl_name, &$tpl_source, &$smarty_obj )
    {
        $tpl_source = $tpl_name;
        return true;
    }

    public function inline_get_timestamp( $tpl_name, &$tpl_timestamp, &$smarty_obj ) {
        $tpl_timestamp = time();
        return true;
    }

    public function inline_get_secure( $tpl_name, &$smarty_obj )
    {
        return true;
    }

    public function inline_get_trusted( $tpl_name, &$smarty_obj )
    {

    }


    protected static $rootDir = "/tmp";

    static public function setRootDir( $rootDir )
    {
        self::$rootDir = $rootDir;
    }

    static public function getInstance( Zend_Config $config = null )
    {
        if ( $config !== null ) { // uggly backward compatibility.
            self::setRootDir( $config->Smarty->root->dir );
        }

        $smarty = new Smarty( );
/*        
        // register the resource name "db"
        $smarty->register_resource( "inline", array( 
                        array( 
                                        $this, 
                                        "inline_get_template" 
                        ), 
                        array( 
                                        $this, 
                                        "inline_get_timestamp" 
                        ), 
                        array( 
                                        $this, 
                                        "inline_get_secure" 
                        ), 
                        array( 
                                        $this, 
                                        "inline_get_trusted" 
                        ) 
        ) );
*/      


        $smarty->template_dir = self::$rootDir . '/templates';
        $smarty->compile_dir = self::$rootDir . '/compile';
        $smarty->config_dir = self::$rootDir . '/config';
        $smarty->cache_dir = self::$rootDir . '/cache';
        $smarty->plugins_dir = array_merge( $smarty->plugins_dir, array(
            0 => self::$rootDir . '/plugins'
            ) );

        return $smarty;
    }
}
